<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
</head>
<body>
<form class="layui-form" lay-filter="formfilter">
    <input type="hidden" name="categoryId">
    <table>
        <tr>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">设备名称：</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">设备编号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="equno" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">资产编号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="fixassetno" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">出厂编号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="factory" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">原厂编号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="oriFacNo" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">折旧方式：</label>
                    <div class="layui-input-block">
                        <input type="text" name="depreciation" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">岗位/位置：</label>
                    <div class="layui-input-block">
                        <input type="text" name="storelocation" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">设备状态：</label>
                    <div class="layui-input-block">
                        <select name="equstatus" lay-filter="aihao">
                            <option value="0">正常</option>
                            <option value="1">维修</option>
                            <option value="2">报废</option>
                        </select>
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">使用状态：</label>
                    <div class="layui-input-block">
                        <select name="eqmUseStatus" lay-filter="aihao">
                            <option value="0">空闲中</option>
                            <option value="1">使用中</option>
                        </select>
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">设备规格：</label>
                    <div class="layui-input-block">
                        <input type="text" name="specification" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">设备型号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="serialno" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>

            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">出厂日期：</label>
                    <div class="layui-input-block">
                        <input type="text" name="manufacturedate" id="chuchangdate" placeholder="yyyy-MM-dd"  autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">设备金融：</label>
                    <div class="layui-input-block">
                        <input type="text" name="price" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">供应商：</label>
                    <div class="layui-input-block">
                        <input type="hidden" name="supperid" id="supplierIds">
                        <input type="text" name="ss" id="suppliers" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">购置日期：</label>
                    <div class="layui-input-block">
                        <input type="text" name="purchasedate" id="gouzhidate" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">精准等级：</label>
                    <div class="layui-input-block">
                        <select name="grade" lay-filter="aihao">
                            <option value="A">A</option>
                            <option value="B">B</option>
                            <option value="C">C</option>
                        </select>
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">资产类别：</label>
                    <div class="layui-input-block">
                        <input type="text" name="eqmClassify" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">入库日期：</label>
                    <div class="layui-input-block">
                        <input type="text" name="storagedate" id="rukudate" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">启用日期：</label>
                    <div class="layui-input-block">
                        <input type="text" name="eqmStartUseDate" id="qiyongdate" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">使用年限：</label>
                    <div class="layui-input-block">
                        <input type="text" name="useLife" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">原值：</label>
                    <div class="layui-input-block">
                        <input type="text" name="originalValue" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">所属部门：</label>
                    <div class="layui-input-block">
                        <input type="hidden" name="dpetids" id="deptIds">
                        <input type="text" name="dd" id="deptname" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">创建人：</label>
                    <div class="layui-input-block">
                        <input type="hidden" name="createUser" id="createId">
                        <input type="text" name="createName" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">经手人：</label>
                    <div class="layui-input-block">
                        <input type="hidden" name="handler" id="handlerId">
                        <input type="text" name="dds" id="handlerName" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
        </tr>
        <tr>

            <td style="text-align: center;font-weight: bold">
                描述：
            </td>
            <td colspan="2">

                <textarea id="demo" name="comments" style="display: none;"></textarea>
            </td>
        </tr>
        <tr>

            <td colspan="3" style="text-align: center">
                <button type="button" class="layui-btn layui-btn-normal" id="next">下一步</button>
                <button type="button" class="layui-btn" id="wancheng">完成</button>
                <button type="button" class="layui-btn layui-btn-danger" id="quexiao">取消</button>
            </td>
        </tr>
    </table>

</form>
<script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>
<script src="../../common/common.js"></script>
<script>

    // 经手人

    // 1. 类型id -- 左树右表中修改
    // 2.创建人 ，登录成功后保存到localStroge
    // 3.富文本编辑器
    var form;
    var layedit;
    var editIndex;
    // 添加
    function addEquip(type){
        // 用于同步编辑器内容到textarea（一般用于异步提交）
        layedit.sync(editIndex);
        // 获取表单数据 -- form.val(filter);
        let val = form.val("formfilter");
        console.log(val);

        $.ajax({
            type:'post',
            url:'/equip/add',
            data:val,
            dataType:'json',
            success:function (res){
                if(type == 0){  // 点击完成
                    if(res.state == '200'){
                        layer.msg(res.msg,{time:500,icon:6})
                    }else{
                        layer.msg(res.msg,{time:500,icon:5})
                    }

                    //关闭当前弹框
                    var index =parent.layer.getFrameIndex(window.name);//先得到当前iframe层的索引
                    parent.layer.close(index);//再执行关闭
                }else{ // 点击下一步

                    if(res.state == '200'){

                        localStorage.setItem("eid",res.eid)
                        localStorage.setItem("ename",res.ename)
                        // 修改路径
                        window.location.href="uploadfile.html";
                    }

                }

            }
        })

    }

    layui.use(['form','layedit','laydate','layer'],function (){
         form = layui.form;
        layedit = layui.layedit;
        var laydate = layui.laydate;
        var layer = layui.layer;
        // 富文本编辑器实例对象


        //创建人 --当前登录的用户
        var uid = localStorage.getItem("uid");
        var uname = localStorage.getItem("uname");

        $("#createId").val(uid);
        $("input[name='createName']").val(uname);


        // 下一步 单击事件
        $("#next").click(function (){

            addEquip(1);

        })


        // 完成的点击事件
        $("#wancheng").click(function (){

            // 调用添加的方法
            addEquip(0);


        })



        $("#handlerName").click(function (){

            layer.open({
                type:2,
                title:'经手人',
                content:'handers.html',
                area:['80%','80%']

            })


        })


        // 所属部门
        $("#deptname").click(function (){
            layer.open({
                type:2,
                title:'部门选择',
                content:"depts.html",
                area:['80%','80%']
            })

        })

// 供应商
        $("#suppliers").click(function (){

            layer.open({
                type:2,
                title:'供应商选择',
                content:"suppliers.html",
                area:['80%','80%']
            })
        })




         editIndex = layedit.build('demo'); //建立编辑器

        laydate.render({
            elem:'#qiyongdate',
            type: 'date'
        })

        laydate.render({
            elem:'#rukudate',
            type: 'date'
        })

        laydate.render({
            elem:'#chuchangdate',
            type: 'date'
        })

        laydate.render({
            elem:'#gouzhidate',
            type: 'date'
        })
    })
</script>
</body>
</html>